﻿using System.Collections.Generic;
using Simple3DRedactor.Domain;

namespace Simple3DRedactor.OpenGLViewer
{
    class ObjectViewFactory : IObjectViewFactory<IOpenGLObjectView>
    {
        public IOpenGLObjectView Create(Sphere obj)
        {
            return new SphereView(obj, this);
        }

        public IOpenGLObjectView Create(Box obj)
        {
            return new BoxView(obj, this);
        }

        public IOpenGLObjectView Create(Cylinder obj)
        {
            return new CylinderView(obj, this);
        }

        public IOpenGLObjectView Create(Light obj)
        {
            return new LightView(obj, this);
        }

        public IOpenGLObjectView Create(MeshObject obj)
        {
            return new MeshObjectView(obj, this);
        }

        private readonly List<IOpenGLObjectView> _objects = new List<IOpenGLObjectView>();
        public int RegisterNewObject(IOpenGLObjectView view)
        {
            _objects.Add(view);
            return _objects.Count;
        }

        public IOpenGLObjectView GetViewById(int id)
        {
            if (id < 1 || id > _objects.Count)
                return null;

            return _objects[id - 1];
        }

        private readonly List<int> _lightIds = new List<int> { 0, 1, 2, 3, 4, 5, 6, 7 };
        public int GetNewLightId()
        {
            var id = _lightIds[0];
            _lightIds.RemoveAt(0);
            return id;
        }

        public void ReturnLightId(int lightId)
        {
            _lightIds.Add(lightId);
        }
    }
}
